package com.cqtczh.qhd.driver.acticity.order;

import httptools.HttpJsonTool;
import imageTools.ImageFactory;

import java.io.File;
import java.lang.reflect.Type;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javabeen.CarTeamIdBeen;
import javabeen.OrderInfoBeen;
import javabeen.PushMessage;
import javabeen.ReceiveOrderMessageBeen;
import javabeen.passlocations;

import org.json.JSONException;
import org.json.JSONObject;

import tools.L;

import View.InPutDialog;
import View.InPutDialog.getUserIntent;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.provider.MediaStore;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.android.pushservice.PushManager;
import com.baidu.lbsapi.auth.LBSAuthManagerListener;
import com.baidu.location.LocationClient;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.utils.DistanceUtil;
import com.baidu.navisdk.BNaviEngineManager.NaviEngineInitListener;
import com.baidu.navisdk.BaiduNaviManager;
import com.baidu.navisdk.BaiduNaviManager.OnStartNavigationListener;
import com.baidu.navisdk.comapi.routeplan.RoutePlanParams.NE_RoutePlan_Mode;
import com.baidu.navisdk.model.RoutePlanModel;
import com.baidu.platform.comapi.map.m;
import com.baidu.platform.comapi.map.t;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.PreferencesCookieStore;
import com.cqtczh.qhd.driver.AppContent;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.acticity.BNavigatorActivity;
import com.cqtczh.qhd.driver.acticity.ImageDetailsActivity;
import com.cqtczh.qhd.driver.acticity.ProjectHomeActivity;
import com.cqtczh.qhd.driver.acticity.ZiFeiActivity;
import com.cqtczh.qhd.driver.acticity.base.BaseActivity;
import com.cqtczh.qhd.driver.api.GagApi;
import com.cqtczh.qhd.driver.model.CarType;
import com.cqtczh.qhd.driver.model.CargoInfo;
import com.cqtczh.qhd.driver.model.MyPosion;
import com.cqtczh.qhd.driver.model.RoutePlanResult;
import com.cqtczh.qhd.driver.model.RoutePlanResult.GetDistance;
import com.cqtczh.qhd.driver.utils.CommonUtil;
import com.cqtczh.qhd.driver.utils.FileUtils;
import com.cqtczh.qhd.driver.utils.OrderSoundRecorder;
import com.cqtczh.qhd.driver.utils.PhotoUtils;
import com.cqtczh.qhd.driver.utils.StringUtils;
import com.cqtczh.qhd.driver.utils.ToastUtils;
import com.cqtczh.qhd.driver.vo.JsonRequest;
import com.cqtczh.qhd.driver.vo.JsonResponse;
import com.cqtczh.qhd.driver.vo.State;

public class OrderDetails extends BaseActivity implements OnClickListener {

	private OrderSoundRecorder orderSoundRecorder;
	private TextView OrderLastTime;
	private String Image_Path;
	private TabHost mTabHost;
	private RadioGroup mRadioGroup;
	private RelativeLayout a11_common, a30_common;
	private TextView title, a12_common;
	private ImageView head_left, head_right;
	private ListView mylist;
	private SimpleAdapter adapter;
	private List<Map<String, Object>> list;
	private String aString;
	private LatLng pt1;
	private LatLng pt2;
	private GeoCoder mSearch = null;
	private double mi = 0.0;
	private int changeId = 0;
	private String carTypeId;
	private int driver_imgone_mark = 0;

	private Thread timethread;
	
	private Button a2_common;
	private Button a1_common;

	private boolean evidencepictureURLComplete = false;

	// private TextView myorder_xiangxi_order;

	private TextView myorder_xiangxi_money;
	private TextView myorder_xiangxi_moneytext;

	private TextView myorder_xiangxi_origin;

	private TextView myorder_xiangxi_zhongdian1;
	private TextView myorder_xiangxi_zhongdian2;
	private TextView myorder_xiangxi_zhongdian3;

	private TextView myorder_xiangxi_payment;

	private TextView myorder_xiangxi_status;

	private TextView myorder_xiangxi_phone;

	private TextView myorder_xiangxi_shrphone;
	private ImageView driver_imgone;

	private TextView senderAdderss_2;
	private TextView myorder_xiangxi_goods, scts, jy;

	private LinearLayout senderPhone;

	private TextView order_State_TextView;
	private ImageView bargain;
	private Gson gson = new Gson();
	private HttpUtils http = new HttpUtils();
	private RequestParams params;
	private AppContent app;
	private PreferencesCookieStore preferencesCookieStore;
	private String orderListId = "";
	private int NewOrderSate;
	private List<OrderInfoBeen> orderDataInfo;

	private RelativeLayout a9_common;
	private String nickBackPZ = GagApi.IMAGE_PAHT_HOST;
	private final String[] arraycargopaytype = new String[] { "线下支付", "在线支付" };

	private final String[] arraycargoisback = new String[] { "有回单", "没有回单" };

	private final String[] arraycargochargetype = new String[] { "到付", "预付" };

	private final String[] arraycargotype = new String[] { "易碎", "易燃", "易爆",
			"一般" };
	private final String[] arraycargoweight = new String[] { "1吨以下", "3吨以内",
			"5吨以内", "5吨以上" };
	private final String[] arraycargovolme = new String[] { "1立方米以内", "3立方米以内",
			"5立方米以内", "5立方米以上" };
	private final String[] arraycargocartype = new String[] { "小箱车(面包,金杯)",
			"0.5T车", "1T车", "2T车", "4T车", "5T车", "8T车" };
	private Bundle bundle2;
	private String[] noticeMsg = new String[] { "无", "无", "无" };
	private final String[] arraycargocarnotice = null;

	private int carTypeIds[] = { 1, 2, 3, 4, 5, 6, 7 };

	private int ownCarTypeId = 0;

	private String intPrice;

	private String istransportOrder = "";

	private RoutePlanModel mRoutePlanModel = null;

	private Bitmap mUserPhoto;

	private String mTakePicturePath = null;

	private boolean mIsEngineInitSuccess = false;

	private RoutePlanSearch mPlanSearch = null;

	private int OrderState;

	private int position;

	EditText c;

	String cargoId;
	private TextView inPutOrigin;

	private TextView senderAdderss_1;

	private TextView senderPhone_1;

	private TextView senderPhone_2;

	private EditText deiver_input_money;

	private String tag = OrderDetails.class.toString();

	private int play_sound_type = -1;
	private boolean is_Show = true;

	private static final String IMAGE_PATH = Environment
			.getExternalStorageDirectory().toString() + GagApi.IMAGE_FILE_PATH;

	boolean showpass = false;

	boolean startThread=true;
	
	boolean getPicture=false;
	
	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SDKInitializer.initialize(getApplicationContext());
		setContentView(R.layout.activity_order_details);
		app = (AppContent) getApplication();
		getIntentBundle(getIntent());
		BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(),
				mNaviEngineInitListener, new LBSAuthManagerListener() {
					@Override
					public void onAuthResult(int status, String msg) {
						String str = null;
						if (0 == status) {
						} else {
						}
					}
				});
		if (savedInstanceState!=null) {
			mTakePicturePath=savedInstanceState.getString("mTakePicturePath");
			BitmapUtils bitmapUtils=new BitmapUtils(this);
			bitmapUtils.display(driver_imgone, mTakePicturePath);
		}
		app.isOrderActivity = true;
		app.OrderId = orderListId;
	}

	private void getIntentBundle(Intent intent) {
		Bundle bundle = intent.getExtras();
		String Is_Play_sound;
		if (mTakePicturePath!=null) {
			mTakePicturePath="";
		}
		
		if (bundle != null) {
			Is_Play_sound = bundle.getString("Is_play_sound");
			c = new EditText(OrderDetails.this);
			PushMessage pushMessage = (PushMessage) bundle
					.getSerializable("orderMessage");
			if (pushMessage != null) {

				if (pushMessage.getOrderId() != 0) {
					orderListId = pushMessage.getOrderId() + "";
					play_sound_type = 1;
				} else if (pushMessage.getListId() != 0) {
					orderListId = pushMessage.getListId() + "";
					play_sound_type = 2;
				} else if (pushMessage.getCompleteOrder() != 0) {
					orderListId = pushMessage.getCompleteOrder() + "";
					play_sound_type = 4;
				} else if (pushMessage.getRejectOrder() != 0) {
					orderListId = pushMessage.getRejectOrder() + "";
					play_sound_type = 3;
				} else if (pushMessage.getRemoveOrder() != 0) {
					orderListId = pushMessage.getRemoveOrder() + "";
					play_sound_type = 5;
				} else if (pushMessage.getNewinfoOrder() != 0) {
					orderListId = pushMessage.getNewinfoOrder() + "";
					play_sound_type = 3;
				}
			} else {
				orderListId = bundle.getInt("OrderId") + "";
			}
			istransportOrder = bundle.getString("istransportOrder");
			if (Is_Play_sound != null && Is_Play_sound.equals("play")) {
				Play_Sound();
			}
		}
		bundle2 = new Bundle();
		initIds();
		if (null != orderListId && !(orderListId.isEmpty())) {
			getPlanDetails();
			L.v("orderListId", "" + orderListId);
		}
	}

	private void Play_Sound() {

		// soundPool.release();

		if (play_sound_type==4) {
			app.new_home_activity_data_has_change=true;
		}
		
		app.PlaySound(play_sound_type);

		PowerManager pm = (PowerManager) getSystemService(OrderDetails.POWER_SERVICE);

		PowerManager.WakeLock wl = pm.newWakeLock(
				PowerManager.ACQUIRE_CAUSES_WAKEUP
						| PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
		wl.acquire();

	}

	private void UploadDriverPrice() {

		String price = deiver_input_money.getText().toString().trim();
		if (price == null) {
			Toast.makeText(this, "请输入价格!", Toast.LENGTH_LONG).show();
			return;
		}
		if ( price.length() <= 0) {
			Toast.makeText(this, "请输入价格!", Toast.LENGTH_LONG).show();
			return;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderListId);
		map.put("userId", app.userId);
		map.put("price", price);
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Toast.makeText(OrderDetails.this, "您的价格已经提交给了货主请等待货主的回复",
							Toast.LENGTH_LONG).show();
					app.OrderActivity_data_has_change = true;
					getPlanDetails();
				}else {
					Toast.makeText(OrderDetails.this, "由于您5分钟内没有对订单进行操作，我们将对您分配新的订单", Toast.LENGTH_LONG).show();
					app.OrderActivity_data_has_change = true;
					OrderDetails.this.finish();
				}
			}
		});
		httpJsonTool.StartWork(map, GagApi.DRIVER_UP_LOAD_PRICE, null, null);

	}
	@SuppressWarnings("unused")
	private void rejectOrder() {
		showLoadingDialog("系统操作中...");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderListId);
		map.put("userId", app.userId);

		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				dismissLoadingDialog();
				if (msg.what == 1) {
					Toast.makeText(OrderDetails.this, "取消完成", Toast.LENGTH_LONG)
							.show();
					app.OrderActivity_data_has_change = true;
					OrderDetails.this.finish();
				}else {
					app.OrderActivity_data_has_change = true;
					Toast.makeText(OrderDetails.this, "取消完成", Toast.LENGTH_LONG).show();
					OrderDetails.this.finish();
				}
			}
		});
		httpJsonTool.StartWork(map, GagApi.REJECT_ORDER, null, null);

	}
	@SuppressWarnings("unused")
	private void transportOrder_unuse() {

		Map<String, Object> map = new HashMap<String, Object>();
		L.v("orderListId", orderListId);
		L.v("userId", app.userId);
		map.put("orderId", orderListId);
		map.put("userId", app.userId);

		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Toast.makeText(OrderDetails.this, "转单完成", Toast.LENGTH_LONG)
							.show();
					// app.OrderActivity_data_has_change=true;
					getPlanDetails();
				}
			}
		});
		httpJsonTool.StartWork(map, GagApi.TRANSPORT_ORDER, null, null);

	}

	private void AcceptOrder() {
		// acceptOdrerShowDialog();
		showLoadingDialog("系统操作中...");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderListId);
		// 这里到底填那个的价格
		map.put("price", orderDataInfo.get(0).getExpectprice() + "");
		map.put("userId", app.userId);
		L.v("接受", "接受");
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				dismissLoadingDialog();
				if (msg.what == 1) {
					Toast.makeText(OrderDetails.this, "订单操作完成",
							Toast.LENGTH_LONG).show();
					getPlanDetails();
					app.OrderActivity_data_has_change = true;
					app.OrderActivity_data_change_poition = "1";
					InPutDialog inPutDialog = new InPutDialog(
							OrderDetails.this, "恭喜您！", "您已经承接该订单，快快运货去吧。",
							null, null);
					is_Show = false;
					inPutDialog.getCheckDialog(true);
					// 这里需要弹出对话框
					// sdfdsf
					// OrderDetails.this.finish();

				} else {
					Toast.makeText(OrderDetails.this, "由于您5分钟内没有对订单进行操作，我们将对您分配新的订单", Toast.LENGTH_LONG).show();
					app.OrderActivity_data_has_change = true;
					OrderDetails.this.finish();
				}
			}
		});
		httpJsonTool.StartWork(map, GagApi.DRIVER_UP_LOAD_PRICE, null, null);
	}

	private void CompleteOrder() {
		if (orderDataInfo.get(0).getNeedreceipt() == null
				|| orderDataInfo.get(0).getNeedreceipt().equals("2")) {
			showLoadingDialog("系统操作中...");
			Map<String, Object> data = new HashMap<String, Object>();
			HttpJsonTool httpJsonTool = new HttpJsonTool(this);
			data.put("orderformid", orderDataInfo.get(0).getOrderformid() + "");
			data.put("carownerid", app.userId);
			httpJsonTool.SetOnLister(new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					dismissLoadingDialog();
					if (msg.what == 1) {
						app.new_home_activity_data_has_change = true;
						app.OrderActivity_data_has_change = true;
						getPlanDetails();
					} else {
						Toast.makeText(OrderDetails.this, "请检查您的网络",
								Toast.LENGTH_LONG).show();
					}
				}
			});

			httpJsonTool.StartWork(data, GagApi.DRIVER_COMPLETE, null, null);
		} else {
			if (orderDataInfo.get(0).getNeedreceipt().equals("1")) {
				if (mTakePicturePath != null && mTakePicturePath.length() > 0) {

				}
				ShowDialog();
			}
		}
	}

	/**
	 * 
	 * @Title: CompleteOrderReceipt
	 * @Description: TODO(完成订单在需要回单的时候)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	private void CompleteOrderReceipt() {
		// 完成订单有回单
		// 弹出提示框
		showLoadingDialog("系统操作中...");
		Map<String, Object> data = new HashMap<String, Object>();
		Map<String, String> imageMap = new HashMap<String, String>();
		if (mTakePicturePath == null || mTakePicturePath.length() <= 0) {
			// CompleteOrderUnderReceipt();
			ShowDialog();
		} else {

			imageMap.put("evidence", mTakePicturePath);
			L.v("evidence", mTakePicturePath);
			HttpJsonTool httpJsonTool = new HttpJsonTool(this);
			data.put("orderformid", orderDataInfo.get(0).getOrderformid() + "");
			data.put("carownerid", app.userId);
			httpJsonTool.SetOnLister(new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					showLoadingDialog("系统操作中...");
					if (msg.what == 1) {
						Toast.makeText(OrderDetails.this, (String) msg.obj,
								Toast.LENGTH_LONG).show();
						getPlanDetails();

					}
				}
			});
			httpJsonTool.StartWork(data, GagApi.DRIVER_COMPLETE_NEED_RECEIPT,
					null, imageMap);
		}
	}


	private TextView senderAdderss_3;

	private TextView senderPhone_3;

	private TextView sender_need_tiem;

	private TextView zf;

	// private void GetOrderLastTime() {
	//
	// app.setGetOrderLastTimeCallBack(new Handler() {
	// @Override
	// public void handleMessage(Message msg) {
	// // TODO Auto-generated method stub
	// super.handleMessage(msg);
	// int time = msg.what;
	// String timeString = time / 60 + "分" + time % 60 + "秒后取消";
	// OrderLastTime.setText("您还没有对订单进行操作将在" + timeString + "后自动取消");
	// if (time == 0) {
	// OrderDetails.this.finish();
	// }
	// }
	// });
	// }

	/*
	 * ************************************新服务器新功能*******************************
	 * ************************************
	 */
	private void initIds() {

		inPutOrigin = (TextView) findViewById(R.id.input_qi_dian);
		OrderLastTime = (TextView) findViewById(R.id.order_Last_Time);

		senderPhone = (LinearLayout) findViewById(R.id.a11_common);
		inPutOrigin = (TextView) findViewById(R.id.input_qi_dian);
		inPutOrigin.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		inPutOrigin.getPaint().setAntiAlias(true);
		// input_qi_dian.setMovementMethod(ScrollingMovementMethod.getInstance());
		TextView sendPhone = (TextView) findViewById(R.id.senderPhone);
		sendPhone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		sendPhone.getPaint().setAntiAlias(true);
		senderAdderss_1 = (TextView) findViewById(R.id.senderAdderss_1);
		senderAdderss_1.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderAdderss_1.getPaint().setAntiAlias(true);
		senderAdderss_2 = (TextView) findViewById(R.id.senderAdderss_2);
		senderAdderss_2.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderAdderss_2.getPaint().setAntiAlias(true);
		senderAdderss_3 = (TextView) findViewById(R.id.senderAdderss_3);
		senderAdderss_3.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderAdderss_3.getPaint().setAntiAlias(true);
		senderPhone_1 = (TextView) findViewById(R.id.senderPhone_1);
		senderPhone_1.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderPhone_1.getPaint().setAntiAlias(true);
		senderPhone_2 = (TextView) findViewById(R.id.senderPhone_2);
		senderPhone_2.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderPhone_2.getPaint().setAntiAlias(true);
		senderPhone_3 = (TextView) findViewById(R.id.senderPhone_3);
		senderPhone_3.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		senderPhone_3.getPaint().setAntiAlias(true);
		deiver_input_money = (EditText) findViewById(R.id.deiver_input_money);


		order_State_TextView = (TextView) findViewById(R.id.Order_State);

		sender_need_tiem = (TextView) findViewById(R.id.sender_need_tiem);
		// dhzd = (LinearLayout) findViewById(R.id.dhzd);
		myorder_xiangxi_origin = (TextView) findViewById(R.id.myorder_xiangxi_origin);
		inPutOrigin.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getPosion(inPutOrigin.getText().toString().trim());
			}
		});

		myorder_xiangxi_moneytext = (TextView) findViewById(R.id.Order_State);

		myorder_xiangxi_money = (TextView) findViewById(R.id.myorder_xiangxi_money);

		// myorder_xiangxi_time = (TextView)
		// findViewById(R.id.myorder_xiangxi_time);
//		pay_type = (TextView) findViewById(R.id.pay_type);
		myorder_xiangxi_goods = (TextView) findViewById(R.id.myorder_xiangxi_goods);
		myorder_xiangxi_phone = (TextView) findViewById(R.id.myorder_xiangxi_phone);
		// sender_pay_money = (TextView) findViewById(R.id.sender_pay_money);

		a2_common = (Button) findViewById(R.id.a2_common_new);
		a1_common = (Button) findViewById(R.id.a1_common_new);
		a2_common.setOnClickListener(new ActionButtonClick());
		a1_common.setOnClickListener(new ActionButtonClick());

		bargain = (ImageView) findViewById(R.id.bargain);

		title = (TextView) findViewById(R.id.head_title);
		title.setText("订单详情");
		head_left = (ImageView) findViewById(R.id.head_left);
		a9_common = (RelativeLayout) findViewById(R.id.a9_common);
		head_left.setVisibility(0);
		head_left.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				OrderDetails.this.finish();
			}
		});
		// 转单不用了
		if (istransportOrder != null) {

			if (istransportOrder.equals("is")) {
				title.setText("转单详情");
			}
		}

		driver_imgone = (ImageView) findViewById(R.id.driver_imgone_new);
		driver_imgone.setOnClickListener(this);

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.jy:
			openActivity(ZiFeiActivity.class);
			break;
		case R.id.head_left:
			finish();
			break;
		case R.id.head_right_img:
			break;
		case R.id.a11_common:
			if (StringUtils.isEmpty(myorder_xiangxi_phone.getText().toString())) {
				showLongToast("寄件人电话为空");
				break;
			}
			if ((OrderState == 5) || (OrderState == 7) || (OrderState == 8)
					|| (OrderState == 9) || (OrderState == 0)) {
				break;
			} else {

				Intent intent = new Intent();
				System.out.println("real电话");
				// 激活源代码,添加intent对象
				intent.setAction("android.intent.action.CALL");
				// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
				intent.setData(Uri.parse("tel:"
						+ myorder_xiangxi_phone.getText().toString()));
				// 激活Intent
				startActivity(intent);
			}
			break;
		case R.id.a30_common:

			if (StringUtils.isEmpty(myorder_xiangxi_shrphone.getText()
					.toString())) {
				showLongToast("收件人电话为空");
				break;
			}
			if ((OrderState == 5) || (OrderState == 7) || (OrderState == 8)
					|| (OrderState == 9) || (OrderState == 0)) {
				break;
			}
			Intent intent9 = new Intent();
			System.out.println("real电话");
			// 激活源代码,添加intent对象
			intent9.setAction("android.intent.action.CALL");
			// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
			intent9.setData(Uri.parse("tel:"
					+ myorder_xiangxi_shrphone.getText().toString()));
			// 激活Intent
			startActivity(intent9);
			break;
		case R.id.myorder_xiangxi_phone:
			System.out.println("myorder_xiangxi_phonetext");
			if ((OrderState == 5) || (OrderState == 7) || (OrderState == 8)
					|| (OrderState == 9) || (OrderState == 0)) {
				break;
			}
			Intent intent2 = new Intent();
			// 激活源代码,添加intent对象
			intent2.setAction("android.intent.action.CALL");
			// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
			intent2.setData(Uri.parse("tel:"
					+ myorder_xiangxi_phone.getText().toString()));
			// 激活Intent
			startActivity(intent2);
			break;
		case R.id.a1_common:

			break;
		case R.id.a2_common:

			// changeList();

			break;
		case R.id.driver_imgone_new:
			if ((driver_imgone_mark == 0) && (OrderState != 3)) {
				updateImg();// 上传凭证
			} else if ((OrderState == 3)) {

			} else {
				Intent intents = new Intent(this, ImageDetailsActivity.class);
				intents.putExtra("path", this.nickBackPZ);
				startActivity(intents);
			}
			break;
		// case R.id.dhqd:
		// getLocation();
		// openActivity(AddCargoMapActivity.class);
		// Intent intent4 = new Intent(this, AddCargoMapActivity.class);
		// startActivityForResult(intent4, 1);
		// break;
		// case R.id.dhzd:
		// openActivity(AddCargoMapActivity.class);
		// getmap();
		// Intent intent5 = new Intent(this, AddCargoMapActivity.class);
		// startActivityForResult(intent5, 2);
		// break;
		default:
			break;
		}
	}

//	private void changeList() {
//		openActivity(AddCargoActivity.class, bundle2);
//		finish();
//	}

	private void getPlanDetails() {
//		if (getPicture) {
//			return;
//		}
		HashMap<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("orderformid", orderListId);
		showLoadingDialog("数据加载中...");
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what != 1) {
					Toast.makeText(OrderDetails.this, (String) msg.obj,
							Toast.LENGTH_LONG).show();
					return;
				}
				orderDataInfo = (List<OrderInfoBeen>) msg.obj;
				if (orderDataInfo.size() > 0) {
					IniUiInfo();
					dismissLoadingDialog();
				} else {
					Toast.makeText(OrderDetails.this, "没有获得订单信息",
							Toast.LENGTH_LONG).show();

				}

			}
		});
		Type type = new TypeToken<List<OrderInfoBeen>>() {}.getType();
		httpJsonTool.StartWork(dataMap, GagApi.GET_ORDER_DETIL, type, null);
	}

	private void IniUiInfo() {
		if (orderDataInfo.size() > 0) {

		} else {
			L.v("orderDataInfo", "orderDataInfo" + "为空");
			return;
		}

		Button upDreiverPrice = (Button) findViewById(R.id.upDreiverPrice);
		upDreiverPrice.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				UploadDriverPrice();
			}
		});

		TextView cargodetil = (TextView) findViewById(R.id.cargodetil);
		if (orderDataInfo.get(0).getCargoremark() != null&&orderDataInfo.get(0).getCargoremark().length()>0) {
			cargodetil.setText(orderDataInfo.get(0).getCargoremark());
		}else {
			View view=findViewById(R.id.cargo_detial);
			view.setVisibility(View.GONE);
		}
		if (orderDataInfo.get(0).getEvidencepictureurl() != null
				&& orderDataInfo.get(0).getEvidencepictureurl().length() > 0) {
			nickBackPZ = orderDataInfo.get(0).getEvidencepictureurl();
		}
		TextView senderPhone = (TextView) findViewById(R.id.senderPhone);
		senderPhone.setText(orderDataInfo.get(0).getCargophone());
		senderPhone.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				// sdfsd
				if ((OrderState == 5) || (OrderState == 7) || (OrderState == 8)) {
					return;
				}
				Intent intent = new Intent();
				// System.out.println("real电话");
				// 激活源代码,添加intent对象
				intent.setAction("android.intent.action.CALL");
				// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
				intent.setData(Uri.parse("tel:"
						+ orderDataInfo.get(0).getCargophone()));
				// 激活Intent
				startActivity(intent);
			}
		});

		driver_imgone = (ImageView) findViewById(R.id.driver_imgone_new);
		BitmapUtils bitmapUtils = new BitmapUtils(this);
		if ((orderDataInfo.get(0).getEvidencepictureurl() != null)) {
			if ((!orderDataInfo.get(0).getEvidencepictureurl().equals("null"))) {
				bitmapUtils.display(driver_imgone, GagApi.IMAGE_PAHT_HOST
						+ orderDataInfo.get(0).getEvidencepictureurl());
				nickBackPZ = GagApi.IMAGE_PAHT_HOST
						+ orderDataInfo.get(0).getEvidencepictureurl();
			}
		}
		OrderState = orderDataInfo.get(0).getState();


		showalertDialog();
		if (OrderState == 2 || OrderState == 1) {
			order_State_TextView.setText("货主更换了议价司机");
//			View driverinputView = findViewById(R.id.driverinputViewFromDriver);
//			driverinputView.setVisibility(View.GONE);
			OrderLastTime.setVisibility(View.GONE);
			viewGone();
			sender_need_tiem.setVisibility(View.VISIBLE);
		}
		if (OrderState == 3) {
		//	OrderLastTime.setVisibility(View.VISIBLE);
			order_State_TextView.setText("议价中");
//			View driverinputView = findViewById(R.id.driverinputViewFromDriver);
//			driverinputView.setVisibility(View.GONE);
			sender_need_tiem.setVisibility(View.VISIBLE);
		}
		if (OrderState == 4) {
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("运送中");
			sender_need_tiem.setVisibility(View.VISIBLE);
			viewGone();
		}
		if (OrderState == 5) {
			// 订单被货主取消
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("货主取消订单");
			viewGone();
			driver_imgone_mark = 1;
		}
		if (OrderState == 6) {
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("转给其他司机中");
			View driverinputView = findViewById(R.id.driverinputView);
			driverinputView.setVisibility(View.GONE);
			a1_common.setVisibility(View.GONE);
		}
		if (OrderState == 7) {
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("已完成");
			viewGone();
			driver_imgone_mark = 1;
		}
		if (OrderState == 8) {
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("货主取消订单");
			viewGone();
			driver_imgone_mark = 1;
		}
		if (OrderState == 9) {
			OrderLastTime.setVisibility(View.GONE);
			order_State_TextView.setText("货主确认中");
			viewGone();
			driver_imgone_mark = 1;
		}
		if (OrderState == 0) {
			OrderLastTime.setVisibility(View.GONE);
			if ((orderDataInfo.get(0).getNeedreceipt() != null)
					&& (orderDataInfo.get(0).getNeedreceipt().equals("1"))) {
				order_State_TextView.setText("货主拒绝回单");
			}
			if ((orderDataInfo.get(0).getNeedreceipt() != null)
					&& (orderDataInfo.get(0).getNeedreceipt().equals("2"))) {
				order_State_TextView.setText("货主未收到货物");
			}
			viewGone();
			driver_imgone_mark = 0;
		}
		TextView needvoucher = (TextView) findViewById(R.id.needvoucher);
		String needString="";
		if ((orderDataInfo.get(0).getNeedreceipt() != null)
				&& ((orderDataInfo.get(0).getNeedreceipt().equals("1")))) {			
			needString=needString+"有回单、";}
//		} else {
//			//TextView needvoucher = (TextView) findViewById(R.id.needvoucher);
//			needString=needString+"无回单";
//		}
		if (orderDataInfo.get(0).getPayment() == 0) {

			needString=needString+"线下货主支付、";
		}

		if (orderDataInfo.get(0).getPayment() == 1) {
			needString=needString+"线下收货人支付、";
		}
//		if (orderDataInfo.get(0).getNeedtransport() == 0) {
//			needString=needString+("不需要搬运");
//		}
		if (orderDataInfo.get(0).getNeedtransport() == 1) {
			needString=needString+"需要搬运";
		}
		needvoucher.setText(needString);

		inPutOrigin.setText(orderDataInfo.get(0).getOrigin());
		NewOrderSate = orderDataInfo.get(0).getState();

		L.v("NewOrderSate", "" + NewOrderSate);
		if (NewOrderSate == 3 || NewOrderSate == 2 || NewOrderSate == 1) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getExpectprice() + "");
			a2_common.setText("拒接");
			a1_common.setText("接受货主价格");
		}

		if (NewOrderSate == 4) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setText("转单");
			a2_common.setVisibility(View.GONE);
			a1_common.setText("货物已经送达");
		}
		if (NewOrderSate == 6) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setText("货物已经送达");
			a1_common.setText("确认");
		}
		if (NewOrderSate == 7) {
			myorder_xiangxi_moneytext.setText("已完成");
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setVisibility(View.GONE);
			a1_common.setVisibility(View.GONE);
		}

		if (NewOrderSate == 8 || NewOrderSate == 1 || NewOrderSate == 2) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setVisibility(View.GONE);
			a1_common.setVisibility(View.GONE);
		}

		if (NewOrderSate == 9) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setVisibility(View.GONE);
			a1_common.setVisibility(View.GONE);
		}

		if (NewOrderSate == 0) {
			myorder_xiangxi_money.setText("￥"
					+ orderDataInfo.get(0).getFinalprice() + "");
			a2_common.setVisibility(View.GONE);
			a1_common.setVisibility(View.VISIBLE);
			if ((orderDataInfo.get(0).getNeedreceipt() != null)
					&& (orderDataInfo.get(0).getNeedreceipt().equals("1"))) {
				a1_common.setText("重新上传回单");
			}
			if ((orderDataInfo.get(0).getNeedreceipt() != null)
					&& (orderDataInfo.get(0).getNeedreceipt().equals("2"))) {
				a1_common.setText("货物送达了");
			}

		}
		TextView cargo_sender_name = (TextView) findViewById(R.id.cargo_sender_name);
		if (orderDataInfo.get(0).getCargoname() != null) {
			cargo_sender_name.setText(orderDataInfo.get(0).getCargoname());
		}

		final List<passlocations> plass = orderDataInfo.get(0)
				.getPasslocations();
		int i = 0;
		for (; i < plass.size(); i++) {
			final String str = plass.get(i).getDestination();
			L.v("出来的", "收货地" + str);
			final String phone = plass.get(i).getReceiverphone();
			final String reciverName = plass.get(i).getReceivername();
			if (i == 0) {
				senderAdderss_1.setText(str);
				if (senderAdderss_1==null) {
					L.v("senderAdderss_1", "为空");
				}else {
					L.v("senderAdderss_1---->", senderAdderss_1.getText().toString());
				}
				senderAdderss_1.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						getPosion(str);
						// byte[] byt=new byte[1];
						// byt[0]=1;

					}
				});
				senderPhone_1.setText(phone);

				senderPhone_1.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Intent intent = new Intent();
						// System.out.println("real电话");
						// 激活源代码,添加intent对象
						// 如果是下面状态的订单就不能够打电话了
						if ((OrderState == 5) || (OrderState == 7)
								|| (OrderState == 8)) {
							return;
						}
						intent.setAction("android.intent.action.CALL");
						// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
						intent.setData(Uri.parse("tel:" + phone));
						// 激活Intent
						startActivity(intent);
					}
				});
				TextView cargoname_1_text = (TextView) findViewById(R.id.cargoname_1_text);
				if (reciverName != null) {
					cargoname_1_text.setText(reciverName);
				}

				sender_need_tiem.setText(orderDataInfo.get(0).getDuedenddate());
			}
			if (i == 1) {
				senderAdderss_2.setText(str);
				senderAdderss_2.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						getPosion(str);
					}
				});
				senderPhone_2.setText(phone);
				senderPhone_2.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						if ((OrderState == 5) || (OrderState == 7)
								|| (OrderState == 8)) {
							return;
						}
						Intent intent = new Intent();
						// System.out.println("real电话");
						// 激活源代码,添加intent对象
						intent.setAction("android.intent.action.CALL");
						// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
						intent.setData(Uri.parse("tel:" + phone));
						// 激活Intent
						startActivity(intent);
					}
				});
				TextView cargoname_2_text = (TextView) findViewById(R.id.cargoname_2_text);
				if (reciverName != null) {
					cargoname_2_text.setText(reciverName);
				}

			}
			if (i == 2) {
				senderAdderss_3.setText(str);
				senderAdderss_3.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						getPosion(str);
					}
				});
				senderPhone_3.setText(phone);
				senderPhone_3.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						if ((OrderState == 5) || (OrderState == 7)
								|| (OrderState == 8)) {
							return;
						}
						Intent intent = new Intent();
						// System.out.println("real电话");
						// 激活源代码,添加intent对象
						intent.setAction("android.intent.action.CALL");
						// intent.addCategory("android.intent.category.DEFAULT");内部会自动添加类别，
						intent.setData(Uri.parse("tel:" + phone));
						// 激活Intent
						startActivity(intent);
					}
				});

				TextView cargoname_3_text = (TextView) findViewById(R.id.cargoname_3_text);
				if (reciverName != null) {
					cargoname_3_text.setText(reciverName);
				}
			}
		}
		L.v("i____>", ""+i);
		if (i == 2) {
			View view = findViewById(R.id.cargo_resave_3);
			view.setVisibility(View.GONE);
		}
		if (i == 1) {
			View view1 = findViewById(R.id.cargo_resave_3);
			view1.setVisibility(View.GONE);
			View view2 = findViewById(R.id.cargo_resave_2);
			view2.setVisibility(View.GONE);
		}

		if (orderDataInfo.get(0).getNeedreceipt() != null) {

			if (orderDataInfo.get(0).getNeedreceipt().equals("2")) {
				View view = findViewById(R.id.driver_up_image);
				view.setVisibility(View.GONE);
			}
		} else {
			View view = findViewById(R.id.driver_up_image);
			view.setVisibility(View.GONE);
		}
		L.v("", "");
		// + orderDataInfo.get(0).getOrderformdata());

//		if (orderDataInfo.get(0).getPayment() == 0) {
//
//			pay_type.setText("线下货主支付");
//		}
//
//		if (orderDataInfo.get(0).getPayment() == 1) {
//		}


//		car_type.setText(orderDataInfo.get(0).getCartypename() + ":"
//				+ orderDataInfo.get(0).getCartypedescription());

		// 发货人电话同时设置打电话的功能myorder_xiangxi_phone
		// myorder_xiangxi_phone.setText(orderDataInfo.get(0).getCargophone());
//		if (orderDataInfo.get(0).getNeedtransport() == 0) {
//		}
//		if (orderDataInfo.get(0).getNeedtransport() == 1) {
//			carrray_man.setText("需要搬运");
//		}

		// carrray_man.setVisibility(View.INVISIBLE);
		// 收货人电话 暂时还没有
		// myorder_xiangxi_shrphone.setText("");
		bargain.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(OrderDetails.this,
						BargainActionActivity.class);
				ReceiveOrderMessageBeen receiveOrderMessageBeen = new ReceiveOrderMessageBeen();
				receiveOrderMessageBeen.setOrderId(orderListId);
				if (orderDataInfo != null) {
					receiveOrderMessageBeen.setReceiver(""
							+ orderDataInfo.get(0).getCargoid());
				} else {
					Toast.makeText(OrderDetails.this, "没有获得货物信息",
							Toast.LENGTH_LONG).show();
					receiveOrderMessageBeen.setReceiver(orderDataInfo.get(0)
							.getCargoownerid());
					receiveOrderMessageBeen.setSender(orderDataInfo.get(0)
							.getCarownerid());
				}
				receiveOrderMessageBeen.setSendertype("2");
				receiveOrderMessageBeen.setReceivertype("1");
				intent.putExtra("MessageData", receiveOrderMessageBeen);
				startActivity(intent);
			}
		});
		// BitmapUtils bitmapUtils = new BitmapUtils(this);
		if (orderDataInfo.get(0).getPhoto1() != null
				&& orderDataInfo.get(0).getPhoto1().length() > 0) {
			ImageView imageView = (ImageView) findViewById(R.id.imageView_photoe1);
			final String path = GagApi.IMAGE_PAHT_HOST
					+ orderDataInfo.get(0).getPhoto1();
			bitmapUtils.display(imageView, path);
			imageView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(OrderDetails.this,
							ImageDetailsActivity.class);
					intent.putExtra("path", path);
					startActivity(intent);
				}
			});
		} else {
			View imageView = findViewById(R.id.imageView_photoe1);
			imageView.setVisibility(View.GONE);
		}
		if (orderDataInfo.get(0).getPhoto2() != null
				&& orderDataInfo.get(0).getPhoto2().length() > 0) {
			ImageView imageView = (ImageView) findViewById(R.id.imageView_photoe2);
			final String path = GagApi.IMAGE_PAHT_HOST
					+ orderDataInfo.get(0).getPhoto2();
			bitmapUtils.display(imageView, path);
			imageView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(OrderDetails.this,
							ImageDetailsActivity.class);
					intent.putExtra("path", path);
					startActivity(intent);
				}
			});
		} else {
			View imageView = findViewById(R.id.imageView_photoe2);
			imageView.setVisibility(View.GONE);
		}
		if (orderDataInfo.get(0).getPhoto2() != null
				&& orderDataInfo.get(0).getPhoto2().length() > 0) {
			ImageView imageView = (ImageView) findViewById(R.id.imageView_photoe3);
			final String path = GagApi.IMAGE_PAHT_HOST
					+ orderDataInfo.get(0).getPhoto3();
			bitmapUtils.display(imageView, path);
			imageView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(OrderDetails.this,
							ImageDetailsActivity.class);
					intent.putExtra("path", path);
					startActivity(intent);
				}
			});
		} else {
			View imageView = findViewById(R.id.imageView_photoe3);
			imageView.setVisibility(View.GONE);
		}
		if (orderDataInfo.get(0).getPhoto2()==null&&orderDataInfo.get(0).getPhoto1()==null&&orderDataInfo.get(0).getPhoto3()==null) {
			View cargo_photoe=findViewById(R.id.cargo_photoe);
			cargo_photoe.setVisibility(View.GONE);
		}
		if (OrderState == 3) {
			// distributetime
			String orderTime = orderDataInfo.get(0).getDistributetime();
			String serviceTime=orderDataInfo.get(0).getServertime();
			if (orderTime==null||orderTime.equals("")) {
				L.v(orderTime, "获得的信息是空");
				
				return;
			}
			if (serviceTime==null||serviceTime.equals("")) {
				return;
			}
			OrderLastTime.setVisibility(View.VISIBLE);
			// OrderTimer orderTimer=new OrderTimer(orderLastTime, handler);
			OrderTimer orderTimer = new OrderTimer(orderTime,serviceTime, new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
//					if (msg.what != -1) {
//						String date = msg.what / 60 + "分" + msg.what % 60 + "秒";
//						OrderLastTime.setText("订单将在" + date + "后取消");
//					}
					if (msg.what==-1) {
						View view=findViewById(R.id.barg_layout);
					//	view.setVisibility(View.GONE);
//						InPutDialog inPutDialog=onew InPutDialog(OrderDetails.this, "请注意", "分配给您的订单超时，系统将重新分配新订单给您", null, null);
//						inPutDialog.setGetUserIntent(new getUserIntent() {
//
//							@Override
//							public void getUserIntentInfo() {
//								// TODO Auto-generated method stub
//								app.OrderActivity_data_has_change=true;
//								OrderDetails.this.finish();
//								Toast.makeText(OrderDetails.this, "请等待系统给您分配的新订单", Toast.LENGTH_LONG).show();
//							}
//						});
//						inPutDialog.getCheckDialog(true);
					}
				}
			});
		//	timethread=new Thread(orderTimer);
		//	timethread.start();
		}	
	}

	private void viewGone() {
		View driverinputView = findViewById(R.id.driverinputView);
		driverinputView.setVisibility(View.GONE);
		View barg_layout = findViewById(R.id.barg_layout);
		barg_layout.setVisibility(View.GONE);
//		View driverinputViewFromDriver = findViewById(R.id.driverinputViewFromDriver);
//		driverinputViewFromDriver.setVisibility(View.GONE);
	}

	private void updateImg() {
		new AlertDialog.Builder(OrderDetails.this)
				.setTitle("上传凭证图片")
				.setItems(new String[] { "拍照上传", "上传手机中的照片" },
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								Intent intent = null;
								switch (which) {
								case 0:
									// mTakePicturePath = null;
									FileUtils.createDirFile(IMAGE_PATH);
									intent = new Intent(
											MediaStore.ACTION_IMAGE_CAPTURE);
									String path = IMAGE_PATH
											+ UUID.randomUUID().toString()
											+ ".jpg";
									File file = FileUtils.createNewFile(path);
									mTakePicturePath = path;
									// System.out.println("[[[[" + path);
									if (file != null) {
										intent.putExtra(
												MediaStore.EXTRA_OUTPUT,
												Uri.fromFile(file));
									}
									getPicture=true;
									startActivityForResult(intent,
											PhotoUtils.INTENT_REQUEST_CODE_CAMERA);
									break;

								case 1:

									Intent intent2 = new Intent(
											Intent.ACTION_PICK, null);
									intent2.setDataAndType(
											MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
											"image/*");
									getPicture=true;
									startActivityForResult(intent2,
											PhotoUtils.INTENT_REQUEST_CODE_ALBUM);
									break;
								}
							}
						})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {

					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}).create().show();

	}

	public class ActionButtonClick implements OnClickListener {

		@Override
		public void onClick(View view) {
			// TODO Auto-generated method stub
			switch (view.getId()) {
			// a2_common是左边

			case R.id.a2_common_new:
				if (NewOrderSate == 2) {
					rejectOrder();
				}
				if (NewOrderSate == 3) {
					rejectOrder();
				}
				if (NewOrderSate == 4) {
				}
				if (NewOrderSate == 6) {
					CompleteOrder();
				}

				break;

			case R.id.a1_common_new:
				if (NewOrderSate == 3) {
					String messages = "您是否接受货主"
							+ orderDataInfo.get(0).getExpectprice() + "元的价格？";
					acceptOdrerShowDialog(messages);
				}
				if (NewOrderSate == 4 || NewOrderSate == 0) {
					L.v("右边边点击了", "右边点击了");
					if (mTakePicturePath != null
							&& mTakePicturePath.length() > 0) {
						CompleteOrderReceipt();
					} else {
						CompleteOrder();
					}

				}
				if (NewOrderSate == 6) {
					AcceptOrder();
				}
			default:
				break;
			}
		}

	}
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		L.v(tag, "onActivityResult" + "不进来");
		switch (requestCode) {

		case PhotoUtils.INTENT_REQUEST_CODE_ALBUM:
			if (data == null) {
				return;
			}
			if (resultCode == RESULT_OK) {
				if (data.getData() == null) {
					return;
				}
				if (!FileUtils.isSdcardExist()) {
					ToastUtils.showLong("SD卡不可用,请检查");
					return;
				}
				Uri uri = data.getData();
				File file = CommonUtil.getFileByUri(this, uri);
				if(file!=null){
					L.v(tag, "图片大小:"+file.length());
					if (file.length() < 50 * 1024) {
						Toast.makeText(this, "图片太小", Toast.LENGTH_LONG).show();
						return;
					}
					mTakePicturePath = file.getPath();
					ImageFactory.compressImage(mTakePicturePath, 10);
					BitmapUtils utils = new BitmapUtils(this);
					utils.display(driver_imgone, mTakePicturePath);
				}
			}
			break;

		case PhotoUtils.INTENT_REQUEST_CODE_CAMERA:
			if (resultCode == RESULT_OK) {
				if (mTakePicturePath != null) {
					ImageFactory.compressImage(mTakePicturePath, 10);
					BitmapUtils utils = new BitmapUtils(this);
					utils.display(driver_imgone, mTakePicturePath);
					/*File f = new File(mTakePicturePath);
					if ((f.length() / 1024) < 50) {
						Toast.makeText(this, "图片太小", Toast.LENGTH_LONG).show();
						mTakePicturePath = null;
					}*/
				}
			} else {
				showLongToast("获取图片失败");
			}
			break;
			
		case PhotoUtils.INTENT_REQUEST_CODE_CROP:
			// System.out.println("2Photoutils进来了");
			if (resultCode == RESULT_OK) {
				String path = data.getStringExtra("path");
				// System.out.println(path);
				if (path != null) {
					Bitmap bitmap = BitmapFactory.decodeFile(path);
					driver_imgone.setImageBitmap(bitmap);
				}
			}
			break;
		default:
			break;
		}


	}

	public String getTakePicturePath() {
		return mTakePicturePath;
	}

	private void startNavi(boolean isReal) {
	}

	private void PlanRoad(LatLng start_point, LatLng end_point) {
		mPlanSearch = RoutePlanSearch.newInstance();
	//	RoutePlanResult result = new RoutePlanResult();
	//	mPlanSearch.setOnGetRoutePlanResultListener(result);
		PlanNode StNode = PlanNode.withLocation(start_point);
		PlanNode EndNode = PlanNode.withLocation(end_point);
		mPlanSearch.drivingSearch((new DrivingRoutePlanOption()).from(StNode)
				.to(EndNode));
	}

	private void initDh(double endlat, double endlng) {
		LatLng p1, p2;
		p1 = new LatLng(app.latitude, app.longitude);
		p2 = new LatLng(endlat, endlng);
		PlanRoad(p1, p2);
		double mi = DistanceUtil.getDistance(p1, p2);
		BaiduNaviManager.getInstance().launchNavigator(this, app.latitude,
				app.longitude, "当前位置", endlat, endlng, "目的地",
				NE_RoutePlan_Mode.ROUTE_PLAN_MOD_MIN_TIME, 
				true, 
				BaiduNaviManager.STRATEGY_FORCE_ONLINE_PRIORITY, 
				new OnStartNavigationListener() { 

					@Override
					public void onJumpToNavigator(Bundle configParams) {
						Intent intent = new Intent(OrderDetails.this,
								BNavigatorActivity.class);
						intent.putExtras(configParams);
						startActivity(intent);
					}

					@Override
					public void onJumpToDownloader() {
					}
				});

	}

	private String getSdcardDir() {
		if (Environment.getExternalStorageState().equalsIgnoreCase(
				Environment.MEDIA_MOUNTED)) {
			return Environment.getExternalStorageDirectory().toString();
		}
		return null;
	}

	private NaviEngineInitListener mNaviEngineInitListener = new NaviEngineInitListener() {
		public void engineInitSuccess() {
			mIsEngineInitSuccess = true;
		}

		public void engineInitStart() {
		}

		public void engineInitFail() {
		}
	};

	private void getPosion(String addr) {

		if ((OrderState == 5) || (OrderState == 7) || (OrderState == 8)
				|| (OrderState == 9) || (OrderState == 0)) {
			return;
		}
		
		String url = "http://api.map.baidu.com/geocoder/v2/?address=" + addr
				+ "&city=重庆市"
				+ "&output=json&ak=cBLvVrFwCIkbG9mFkAm9uHNB";
		
		url = url.replaceAll(" ", "");
		
		http.send(HttpRequest.HttpMethod.GET, url, null,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {

						
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						 System.out.println(responseInfo.result);
						 L.v("responseInfo",responseInfo.result);
						MyPosion myPosion = null;
						try {
							myPosion = gson2.fromJson(
									new JSONObject(responseInfo.result)
											.getJSONObject("result")
											.getJSONObject("location")
											+ "", MyPosion.class);
						} catch (JsonSyntaxException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						if (null != myPosion) {
							// PlanRoad(myPosion.getLat(),myPosion.getLng());
							initDh(myPosion.getLat(), myPosion.getLng());
						} else
							showLongToast("该地址无法发起导航");

					}

					@Override
					public void onFailure(HttpException error, String msg) {

					}
				});
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		if (app.New_Order_Push) {
	
			app.New_Order_Push = true;
			showpass = true;
			if (!getPicture) {
			
				getPlanDetails();
			}else {
				showpass = false;
			}
			if (play_sound_type!=-1) {
				showpass = false;
			}
		}
	}

	@Override
	protected void onDestroy() {

		super.onDestroy();

	}

	
	private void acceptOdrerShowDialog(String messages) {
		LayoutInflater inflater = LayoutInflater.from(OrderDetails.this);
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.alert_dialog, null);
		final Dialog isExit = new AlertDialog.Builder(OrderDetails.this)
				.create();
		isExit.show();
		isExit.setContentView(layout);

		TextView title = (TextView) layout.findViewById(R.id.title);
		TextView message = (TextView) layout.findViewById(R.id.message);
		title.setText("请注意");

		message.setText(messages);
		Button check = (Button) layout.findViewById(R.id.check);
		Button giveup = (Button) layout.findViewById(R.id.giveup);
		check.setText("确定");
		giveup.setText("取消");
		check.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				isExit.dismiss();
				// updateImg();
				// return true;
				AcceptOrder();
			}
		});
		giveup.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				isExit.dismiss();
				// return false;
			}
		});
	}

	
	private void ShowDialog() {
		LayoutInflater inflater = LayoutInflater.from(OrderDetails.this);
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.alert_dialog, null);
		final Dialog isExit = new AlertDialog.Builder(OrderDetails.this)
				.create();
		isExit.show();
		isExit.setContentView(layout);

		TextView title = (TextView) layout.findViewById(R.id.title);
		TextView message = (TextView) layout.findViewById(R.id.message);
		title.setText("提醒");

		message.setText("订单需要回单请拍照");
		Button check = (Button) layout.findViewById(R.id.check);
		Button giveup = (Button) layout.findViewById(R.id.giveup);
		check.setText("确定");
		giveup.setText("取消");
		check.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				isExit.dismiss();
				updateImg();

			}
		});
		giveup.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				isExit.dismiss();
			}
		});
	}

	@Override
	protected void onNewIntent(Intent intent) {
		// TODO Auto-generated method stub
		super.onNewIntent(intent);
		// onCreate(null);
		showpass = false;
		showUI();
		setContentView(R.layout.activity_order_details);
		getIntentBundle(intent);		
	}

	private void showUI(){
		View view=findViewById(R.id.barg_layout);
		view.setVisibility(View.VISIBLE);
		a2_common.setVisibility(View.VISIBLE);
		a1_common.setVisibility(View.VISIBLE);
		View driverinputView = findViewById(R.id.driverinputView);
		driverinputView.setVisibility(View.VISIBLE);
//		View barg_layout = findViewById(R.id.barg_layout);
//		barg_layout.setVisibility(View.GONE);
//		View driverinputViewFromDriver = findViewById(R.id.driverinputViewFromDriver);
//		driverinputViewFromDriver.setVisibility(View.GONE);
		
	}
	
	
	private void showalertDialog() {
		String title = "", pMessage = "";

		switch (OrderState) {
		case 1:

			break;
		case 2:

			title = "订单被货主取消";
			pMessage = "您的订单被货主取消了，我们将分配给您新的订单";
			L.v(title, pMessage);
			break;
		case 3:
			title = "新的订单";
			pMessage = "请接单或议价";
			break;
		case 4:                                                              
			title = "恭喜您！";
			pMessage = "您已经承接该订单，快快运货去吧。";
			break;
		case 5:
			title = "订单失效";
			pMessage = "您的订单被货主取消了，我们将分配给您新的订单";
			L.v(title, pMessage);
			break;
		case 6:
		
			break;
		case 7:
			title = "感谢您使用Q货的";
			pMessage = "您的订单已经被货主确认，此单完成";
			break;
		case 8:

			title = "订单被货主取消";
			pMessage = "您的订单被货主取消了，我们将分配给您新的订单";
			L.v(title, pMessage);
			break;
		case 9:
			title = "货主确认中";
			pMessage = "货主正在确认您的订单";
			break;
		case 0:
			title = "请注意！！！";
			pMessage = "货主提出没有收到货或者回单错误请检查";
			break;
		default:
			break;
		}
		L.v("showpass", ""+showpass);
		L.v("play_sound_type", ""+play_sound_type);
		if (is_Show) {
			if (!showpass) {
				if ((play_sound_type != -1) && (play_sound_type != 2)) {
					if ((!title.equals("")) && (!pMessage.equals(""))) {
						L.v(title, pMessage);
						InPutDialog inPutDialog = new InPutDialog(this, title,
								pMessage, null, null);
						inPutDialog.getCheckDialog(true);
						play_sound_type = -1;
					}
				}
				if ((OrderState == 3) && (play_sound_type == 2)) {
					title = "请注意！";
					pMessage = "货主给您发送了一条议价消息，请点击议价按钮查看";
					InPutDialog inPutDialog = new InPutDialog(this, title,
							pMessage, null, null);
					inPutDialog.getCheckDialog(true);
					play_sound_type = -1;
				}
				if ( (play_sound_type == 4)) {
					title = "恭喜您！！！";
					pMessage = "货主已经确认你的订单，此单已经完成。";
					InPutDialog inPutDialog = new InPutDialog(this, title,
							pMessage, null, null);
					inPutDialog.getCheckDialog(true);
					play_sound_type = -1;
				}
			}
		} else {
			is_Show = true;
		}
	}

	class OrderTimer implements Runnable {
		int list_id;
		int morderLastTime;
		Handler mhandler;

		public OrderTimer(String morderLastTime,String serverTime, Handler handler) {
			// this.morderLastTime = morderLastTime;
			this.mhandler = handler;
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			L.v("OrderTimer", morderLastTime);
			try {
				Date date = dateFormat.parse(morderLastTime);
				Date mdate = dateFormat.parse(serverTime);
				this.morderLastTime = (int) ((mdate.getTime() - date.getTime()) / 1000);
				L.v("OrderTimer", "-->"+this.morderLastTime);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			 int cutt = 360;
			 cutt=cutt-morderLastTime;
			L.v("OrderTimer", "<--->"+cutt);
			while ((cutt > 0)&&(startThread)) {
				try {
					// morderLastTime = cutt;
					L.v("OrderTimer", "--->"+cutt);
					Thread.sleep(1000);
					mhandler.sendEmptyMessage(cutt);
					cutt--;
					// L.v("OrderTimer", "Runnable"+cutt);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (cutt == 0) {
				// 如果时间到了那么就拒接订单
				// rejectOrder();
				mhandler.sendEmptyMessage(-1);
			}
		}
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub
		outState.putString("mTakePicturePath", mTakePicturePath);
		super.onSaveInstanceState(outState);
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();

		startThread=false;	
	}

}
